{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Capital BikeShare"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 1、导入必要的工具包"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import numpy as np  # 矩阵操作\n",
    "import pandas as pd # SQL数据处理\n",
    "import matplotlib.pyplot as plt   #画图\n",
    "import seaborn as sns\n",
    "\n",
    "from sklearn.metrics import r2_score  #评价回归预测模型的性能\n",
    "\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 2、数据探索"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.1 读取数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>instant</th>\n",
       "      <th>dteday</th>\n",
       "      <th>season</th>\n",
       "      <th>yr</th>\n",
       "      <th>mnth</th>\n",
       "      <th>holiday</th>\n",
       "      <th>weekday</th>\n",
       "      <th>workingday</th>\n",
       "      <th>weathersit</th>\n",
       "      <th>temp</th>\n",
       "      <th>atemp</th>\n",
       "      <th>hum</th>\n",
       "      <th>windspeed</th>\n",
       "      <th>casual</th>\n",
       "      <th>registered</th>\n",
       "      <th>cnt</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2011-01-01</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.344167</td>\n",
       "      <td>0.363625</td>\n",
       "      <td>0.805833</td>\n",
       "      <td>0.160446</td>\n",
       "      <td>331</td>\n",
       "      <td>654</td>\n",
       "      <td>985</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>2011-01-02</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>0.363478</td>\n",
       "      <td>0.353739</td>\n",
       "      <td>0.696087</td>\n",
       "      <td>0.248539</td>\n",
       "      <td>131</td>\n",
       "      <td>670</td>\n",
       "      <td>801</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>2011-01-03</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.196364</td>\n",
       "      <td>0.189405</td>\n",
       "      <td>0.437273</td>\n",
       "      <td>0.248309</td>\n",
       "      <td>120</td>\n",
       "      <td>1229</td>\n",
       "      <td>1349</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>2011-01-04</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.200000</td>\n",
       "      <td>0.212122</td>\n",
       "      <td>0.590435</td>\n",
       "      <td>0.160296</td>\n",
       "      <td>108</td>\n",
       "      <td>1454</td>\n",
       "      <td>1562</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>2011-01-05</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>0.226957</td>\n",
       "      <td>0.229270</td>\n",
       "      <td>0.436957</td>\n",
       "      <td>0.186900</td>\n",
       "      <td>82</td>\n",
       "      <td>1518</td>\n",
       "      <td>1600</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   instant      dteday  season  yr  mnth  holiday  weekday  workingday  \\\n",
       "0        1  2011-01-01       1   0     1        0        6           0   \n",
       "1        2  2011-01-02       1   0     1        0        0           0   \n",
       "2        3  2011-01-03       1   0     1        0        1           1   \n",
       "3        4  2011-01-04       1   0     1        0        2           1   \n",
       "4        5  2011-01-05       1   0     1        0        3           1   \n",
       "\n",
       "   weathersit      temp     atemp       hum  windspeed  casual  registered  \\\n",
       "0           2  0.344167  0.363625  0.805833   0.160446     331         654   \n",
       "1           2  0.363478  0.353739  0.696087   0.248539     131         670   \n",
       "2           1  0.196364  0.189405  0.437273   0.248309     120        1229   \n",
       "3           1  0.200000  0.212122  0.590435   0.160296     108        1454   \n",
       "4           1  0.226957  0.229270  0.436957   0.186900      82        1518   \n",
       "\n",
       "    cnt  \n",
       "0   985  \n",
       "1   801  \n",
       "2  1349  \n",
       "3  1562  \n",
       "4  1600  "
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data = pd.read_csv(\"day.csv\")\n",
    "data_copy = pd.read_csv(\"day.csv\")\n",
    "data.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "###  2.2 数据基本信息\n",
    "样本数目、特征维数\n",
    "每个特征的类型、空值样本的数目、数据类型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "del data['dteday']\n",
    "del data['instant']\n",
    "del data['atemp']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['season', 'mnth', 'holiday', 'weekday', 'workingday', 'weathersit',\n",
       "       'temp', 'hum', 'windspeed'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "X = data.drop(['yr','casual','registered','cnt'], axis = 1)\n",
    "\n",
    "#用于后续显示权重系数对应的特征\n",
    "columns = X.columns\n",
    "columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.3 数据准备"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/lihuixiang/anaconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:444: DataConversionWarning: Data with input dtype int64 was converted to float64 by the scale function.\n",
      "  warnings.warn(msg, DataConversionWarning)\n"
     ]
    }
   ],
   "source": [
    "# 按年份分离train & test data\n",
    "data_train=data[data.yr<1]\n",
    "data_test=data[data.yr>0]\n",
    "\n",
    "# y 值输入 + 两年的数值范围不易，做均值补偿\n",
    "# from sklearn.preprocessing import Normalizer\n",
    "y_train = data_train['cnt'].values\n",
    "y_test = data_test['cnt'].values\n",
    "# y_train\n",
    "# y_train = Normalizer().fit_transform(y_train.reshape(-1,1)) \n",
    "# y_test = Normalizer().transform(y_test.reshape(-1,1))\n",
    "# from sklearn.preprocessing import Normalizer\n",
    "# y_train=Normalizer().fit_transform(y_train.reshape(-1,1))\n",
    "# y_test=Normalizer().fit_transform(y_test.reshape(-1,1))\n",
    "\n",
    "from sklearn import preprocessing\n",
    "y_train = preprocessing.scale(y_train.reshape(-1, 1))\n",
    "y_test = preprocessing.scale(y_test.reshape(-1, 1))\n",
    "\n",
    "# define value features\n",
    "columns_num = ['mnth','holiday','weekday','workingday','season','weathersit','cnt','yr','registered','casual']\n",
    "columns_onehot=['cnt','yr','registered','casual','temp','hum','windspeed']\n",
    "# seperate x into to catagories, one with value features, another contains classfied features\n",
    "X_train_onehot=data_train.drop(columns_onehot,axis=1)\n",
    "X_train_num=data_train.drop(columns_num,axis=1)\n",
    "X_test_onehot=data_test.drop(columns_onehot,axis=1)\n",
    "X_test_num=data_test.drop(columns_num,axis=1)\n",
    "\n",
    "# onehotencoder the x which contains classified features\n",
    "from sklearn.preprocessing import OneHotEncoder\n",
    "X_train_onehot=OneHotEncoder(sparse=False).fit_transform(X_train_onehot)\n",
    "X_test_onehot=OneHotEncoder(sparse=False).fit_transform(X_test_onehot)\n",
    "# X_train_onehot=OneHotEncoder().fit_transform(X_train_onehot)\n",
    "# X_test_onehot=OneHotEncoder().fit_transform(X_test_onehot)\n",
    "\n",
    "# X_train_onehot=pd.DataFrame(OneHotEncoder().fit_transform(X_train_onehot).toarray())\n",
    "# X_test_onehot=pd.DataFrame(OneHotEncoder().fit_transform(X_test_onehot).toarray())\n",
    "\n",
    "\n",
    "#Normalize the x which contains value features\n",
    "from sklearn.preprocessing import Normalizer\n",
    "X_train_num=Normalizer().fit_transform(X_train_num)\n",
    "X_test_num=Normalizer().fit_transform(X_test_num)\n",
    "\n",
    "# from sklearn import preprocessing\n",
    "# enc = preprocessing.OneHotEncoder()\n",
    "# #onehot = pd.DataFrame(enc.fit_transform(data[['season','mnth','weekday','weathersit']]).toarray())\n",
    "# data22=data[['season','mnth','weekday','weathersit']]\n",
    "# onehot = pd.DataFrame(enc.fit_transform(X_train_onehot).toarray())\n",
    "\n",
    "# onehot\n",
    "\n",
    "# # data_temp = data.drop(['season','mnth','weekday','weathersit'], axis = 1)\n",
    "# data_new = pd.concat([X_train_num, X_train_onehot],axis=1 )  #与独热编码的数据合并\n",
    "\n",
    "# data22=data[['season','mnth','weekday','weathersit']]\n",
    "# data11=data_train.drop(columns_onehot,axis=1)\n",
    "#data22"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(365, 3)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# verify shape of two Xs\n",
    "X_train_num.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.,  0.,  0., ...,  0.,  1.,  0.],\n",
       "       [ 1.,  0.,  0., ...,  0.,  1.,  0.],\n",
       "       [ 1.,  0.,  0., ...,  1.,  0.,  0.],\n",
       "       ..., \n",
       "       [ 1.,  0.,  0., ...,  1.,  0.,  0.],\n",
       "       [ 1.,  0.,  0., ...,  1.,  0.,  0.],\n",
       "       [ 1.,  0.,  0., ...,  1.,  0.,  0.]])"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# verify shape of two Xs\n",
    "X_train_onehot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 1.        ,  0.        ,  0.        , ...,  0.38634844,\n",
       "         0.90459666,  0.18011042],\n",
       "       [ 1.        ,  0.        ,  0.        , ...,  0.44129317,\n",
       "         0.84510875,  0.30174746],\n",
       "       [ 1.        ,  0.        ,  0.        , ...,  0.36374692,\n",
       "         0.8100095 ,  0.45997043],\n",
       "       ..., \n",
       "       [ 1.        ,  0.        ,  0.        , ...,  0.38993074,\n",
       "         0.901553  ,  0.18749989],\n",
       "       [ 1.        ,  0.        ,  0.        , ...,  0.43198526,\n",
       "         0.8824507 ,  0.18619746],\n",
       "       [ 1.        ,  0.        ,  0.        , ...,  0.53116203,\n",
       "         0.79782221,  0.28521328]])"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# merge two Xs\n",
    "X_train=np.hstack((X_train_onehot,X_train_num))\n",
    "X_test=np.hstack((X_test_onehot,X_test_num))\n",
    "X_train\n",
    "\n",
    "\n",
    "# from scipy.sparse import hstack \n",
    "# X_train=hstack((X_train_num,X_train_onehot))\n",
    "# X_test=hstack((X_test_num,X_test_onehot))\n",
    "\n",
    "# X_train=pd.concat([X_train_onehot,X_train_num],axis=1)\n",
    "# X_train"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 3、确定模型类型"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.1 尝试缺省参数的线性回归"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "scrolled": true
   },
   "outputs": [],
   "source": [
    "# 线性回归\n",
    "#class sklearn.linear_model.LinearRegression(fit_intercept=True, normalize=False, copy_X=True, n_jobs=1)\n",
    "from sklearn.linear_model import LinearRegression\n",
    "\n",
    "# 使用默认配置初始化\n",
    "lr = LinearRegression()\n",
    "\n",
    "# 训练模型参数\n",
    "lr.fit(X_train, y_train)\n",
    "\n",
    "# 预测\n",
    "y_test_pred_lr = lr.predict(X_test)\n",
    "y_train_pred_lr = lr.predict(X_train)\n",
    "\n",
    "# columns=X_train.columns\n",
    "\n",
    "# # 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "# fs = pd.DataFrame({\"columns\":list(columns), \"coef\":list((lr.coef_.T))})\n",
    "# fs.sort_values(by=['coef'],ascending=False)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.1.1 模型评价"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LinearRegression on test is 0.709068915414\n",
      "The r2 score of LinearRegression on train is 0.847418696816\n"
     ]
    }
   ],
   "source": [
    "# 使用r2_score评价模型在测试集和训练集上的性能，并输出评估结果\n",
    "#测试集\n",
    "print ('The r2 score of LinearRegression on test is', r2_score(y_test, y_test_pred_lr))\n",
    "#训练集\n",
    "print ('The r2 score of LinearRegression on train is', r2_score(y_train, y_train_pred_lr))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAekAAAFsCAYAAADos0H8AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAG4lJREFUeJzt3X+UV3W97/HnW5igIwqBoAgVUFr+BGwkyDSKSgsTzz2V\ndf2BS9SyOstTt1/W7Th56lRLb928Wet4rNS0RLmn8NRpHb0kh/SWnhkjf2FBJjeQYKT8gWkCvu8f\n3w0NMMN8Gb4z82Hm+Vhr1nf/+u79/uw9M6/57L2/eyIzkSRJ5dmvvwuQJEmdM6QlSSqUIS1JUqEM\naUmSCmVIS5JUKENakqRCGdIa9CLiwYiY3d919KeI+OuI+F1EbIqI6X243U0RMaWLeedGxJ0N2s6j\nEfHmRqxL6kuGtAa0zn457/zLPzOPysyl3axnUkRkRAztpVL72xXAhzJzRGb+YueZVdufqUJ1bUR8\nOSKG7O1Gq+09srfrkQYqQ1oqQAHh/3LgwW6WmZqZI4A3AGcA5/V6VdIgZ0hr0OvY246IGRHRGhFP\nRcT6iPhytdiy6vWJqjc5KyL2i4j/HhGrI2JDRFwfESM7rPecat7GiPjMTttpiYhFEXFDRDwFnFtt\n+2cR8URErIuIr0XEizqsLyPiAxGxMiKejoh/iIhXVO95KiJu7rj8Tm3stNaIGBYRm4AhwC8j4jfd\n7a/MXAXcBUzrsP6REfHNqu61EfG5bT3tiHhlRPxHRDwZEY9HxMKd2vTKanhMRNxateUe4BUdltvl\nTEZELI2I86vhV0TET6p9/XhE3BgRo7rY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ssst4/etfzy233FJXLfXydLckaQdbt25lyZIlLFiwAIDbbruNlStXcs8995CZnHbaaSxb\ntoz29nYOPfRQfvSjHwHw5JNP7rCedevWcemll9LW1sbIkSN54xvfyPTp03e77eHDh/P973+fAw88\nkMcff5yZM2dy2mmn7XAT1ne/+11OPvlkPv3pT7N161b+9Kc/9aidDz/8MHfccQdPP/00r3rVq7jo\nootYtWoVCxcu5K677qKpqYkPfOAD3HjjjZxzzjl8/vOfZ/To0WzdupU5c+Zw3333ceyxx26v+847\n7+xRHbtjSEuSAHj22WeZNm0ajz76KK95zWt4y1veAtRC+rbbbtsesJs2bWLlypWceOKJfPSjH+UT\nn/gEp556KieeeOIO67v77ruZPXs2Y8fW/uHTGWecwa9//evd1pCZfOpTn2LZsmXst99+rF27lvXr\n13PIIYdsX+b444/nvPPOY/PmzZx++ulMmzatR+2dO3cuw4YNY9iwYYwbN47169ezZMkS2traOP74\n47fvk3HjxgFw8803c/XVV7NlyxbWrVvHQw89tD2kzzjjjB7V0B1Pd0uSgL9ck169ejXPP//89mvS\nmckll1zC8uXLWb58OatWrWLBggUcfvjhtLW1ccwxx3DJJZdw2WWX7bLOrj6GNHToUF544YXt63/+\n+ecBuPHGG2lvb6etrY3ly5dz8MEH7/JZ45NOOolly5YxYcIEzj77bK6//voetXfYsGHbh4cMGcKW\nLVvITObPn7+9rb/61a9oaWnht7/9LVdccQVLlizhvvvuY+7cuTvUtf/++/eohu7Yk5bUJ/bkbuVG\n39msPTNy5EiuvPJK5s2bx0UXXcTJJ5/MZz7zGc4880xGjBjB2rVraWpqYsuWLYwePZqzzjqLESNG\ncO211+6wnte+9rVcfPHFbNy4kQMPPJBbbrmFqVOnArXruG1tbbz73e9m8eLFbN68GaidMh83bhxN\nTU3ccccdrF696391XL16NRMmTOCCCy7gmWee4d577+Wcc85pSNvnzJnDvHnz+PCHP8y4ceP4wx/+\nwNNPP81TTz3F/vvvz8iRI1m/fj0//vGPmT17dkO2uTuGtCQVqL//UJk+fTpTp07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+Gtqf2H+GVgP/Hs1/VDg36rhKcAvq68HqZ0u7vfa\ne7vd1fjbgV9T60UOhHaPoXZX98rqdXQ1vRm4php+HXB/dbzvBxb0d9170d5djh9wGXBaNTwcuAVY\nBdwDTOnvmvuo3V+ofpZ/CdwBvLq/a25Am78HrAM2Vz/bC4D3A++v5ge1u95/U31fN/d3zX3U7g91\nONY/B17XV7X5WFBJkgrl6W5JkgplSEuSVChDWpKkQhnSkiQVypCWJKlQhrQkSYUypCVJKtT/B7e3\nVpSjHDA4AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a16caab38>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#在训练集上观察预测残差的分布，看是否符合模型假设：噪声为0均值的高斯噪声\n",
    "f, ax = plt.subplots(figsize=(7, 5)) \n",
    "f.tight_layout() \n",
    "ax.hist(y_train - y_train_pred_lr,bins=40, label='Residuals Linear', color='b', alpha=.5); \n",
    "ax.set_title(\"Histogram of Residuals\") \n",
    "ax.legend(loc='best');"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "残差分布和高斯分布比较匹配，但还是左skew，可能是由于数据集中有16个数据的y值为最大值，有噪声（预测残差超过2.5）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAARgAAADQCAYAAADcQn7hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xt4VPW18PHvmmHIhVuAgEBEodWiAnJVUY5VqRYUFaQq\ncKwv1NbWt9Yeq1LxXmo9ULHCae3rqQVPlWq9obRAFQWsVRSQm0SL9AgoEhUIIcSQ2ySz3j9mQifJ\nnlsykz3JrM/z8JBJZvZegczK77p+oqoYY0wqeNwOwBjTflmCMcakjCUYY0zKWIIxxqSMJRhjTMpY\ngjHG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Va1T1eEEW9hnikjMCpPxcKvgVFKo6oVxPvVpYCXgWPc31XGIyAzgUuAbGuropkoC/yatbR/QP+zx\n8cBnLsWSNkTERzC5PKWqL7odj6qWisjfgAlAiwfB23QLJpp0KcspIhOA24HLVbXCjRjSxLvAySIy\nUEQ6AtOAv7gck6skeALgYmCHqj7sYhy96mc3RSQHuJAkvV/a7UpeEVlKcMbkWFlOVS1yIY6PgCzg\nUOhT61XVlRKhInIF8BugF1AKbFPV8a14/0uAhQRnlB5X1Qda696N4vgTcD7B0gT7gftUdbELcfwb\n8CZQSPDnFOBOVf1rK8dxOvAEwf8XD/Ccqv48KddurwnGGOO+dttFMsa4zxKMMSZlLMEYY1LGEowx\nJmUswRhjUqZNL7Qz7hORnsCa0MM+QB1wMPT4zNC+I5OhbJraJI2I/AwoV9WHGn1eCP6sBRxfaNot\n6yKZlBCRk0J7oP4b2AL0F5HSsK9PE5FFoY+PE5EXRWRTqC7JGLfiNsllCcak0mnAYlUdAURbRf1r\n4EENnsdzNbCoNYIzqWdjMCaVdqnqu3E870JgULAnBUB3EclR1crUhWZagyUYk0pHwz4O0LBkQ3bY\nx4INCLdL1kUyrSI0wHtYRE4WEQ9wRdiXVwM31j8QkeGtHZ9JDUswpjXdDrxCcFp7X9jnbwTGhgqj\n/wO43o3gTPLZNLUxJmWsBWOMSRlLMMaYlLEEY4xJGUswxpiUsQRjjEkZSzDGmJSxBGOMSZn/D3FD\nP5wRjD4gAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a16e2c7b8>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#还可以观察预测值与真值的散点图\n",
    "plt.figure(figsize=(4, 3))\n",
    "plt.scatter(y_train, y_train_pred_lr)\n",
    "plt.plot([-3, 3], [-3, 3], '--k')   #数据已经标准化，3倍标准差即可\n",
    "plt.axis('tight')\n",
    "plt.xlabel('True ')\n",
    "plt.ylabel('Predicted ')\n",
    "plt.tight_layout()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "在y的真值大的部分预测效果不好"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/lihuixiang/anaconda3/lib/python3.6/site-packages/sklearn/utils/validation.py:547: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
      "  y = column_or_1d(y, warn=True)\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "array([-0.49091907, -0.17101412,  0.12044039,  0.33692947, -0.61045834,\n",
       "       -0.51078136, -0.4045824 ,  0.01640918,  0.6429165 ,  0.53710021,\n",
       "        0.06295215,  0.08554898,  0.34942429,  0.1167971 , -0.21546274,\n",
       "       -0.2744269 , -0.0255174 , -0.17904592, -0.03354556, -0.04941865,\n",
       "       -0.02094239, -0.05523509, -0.07462323, -0.03110139,  0.06030298,\n",
       "       -0.1522885 , -0.05227482,  0.44990299,  0.20026953, -0.85473585,\n",
       "        1.48763534, -0.65651939, -0.94969637])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 线性模型，随机梯度下降优化模型参数\n",
    "# 随机梯度下降一般在大数据集上应用，其实本项目不适合用\n",
    "from sklearn.linear_model import SGDRegressor\n",
    "\n",
    "# 使用默认配置初始化线\n",
    "sgdr = SGDRegressor(max_iter=1000)\n",
    "\n",
    "# 训练：参数估计\n",
    "sgdr.fit(X_train, y_train)\n",
    "\n",
    "# 预测\n",
    "#sgdr_y_predict = sgdr.predict(X_test)\n",
    "\n",
    "sgdr.coef_"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The value of default measurement of SGDRegressor on test is 0.681707199707\n",
      "The value of default measurement of SGDRegressor on train is 0.844097222415\n"
     ]
    }
   ],
   "source": [
    "# 使用SGDRegressor模型自带的评估模块(评价准则为r2_score)，并输出评估结果\n",
    "print ('The value of default measurement of SGDRegressor on test is', sgdr.score(X_test, y_test))\n",
    "print ('The value of default measurement of SGDRegressor on train is', sgdr.score(X_train, y_train))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#这里由于样本数不多，SGDRegressor可能不如LinearRegression。 sklearn建议样本数超过10万采用SGDRegressor"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.2 正则化的线性回归（L2正则 --> 岭回归）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "scrolled": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of RidgeCV on test is 0.709273394157\n",
      "The r2 score of RidgeCV on train is 0.849328204483\n"
     ]
    }
   ],
   "source": [
    "#岭回归／L2正则\n",
    "#class sklearn.linear_model.RidgeCV(alphas=(0.1, 1.0, 10.0), fit_intercept=True, \n",
    "#                                  normalize=False, scoring=None, cv=None, gcv_mode=None, \n",
    "#                                  store_cv_values=False)\n",
    "from sklearn.linear_model import  RidgeCV\n",
    "\n",
    "#设置超参数（正则参数）范围\n",
    "alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "#n_alphas = 20\n",
    "#alphas = np.logspace(-5,2,n_alphas)\n",
    "\n",
    "#生成一个RidgeCV实例\n",
    "ridge = RidgeCV(alphas=alphas, store_cv_values=True)  \n",
    "\n",
    "#模型训练\n",
    "ridge.fit(X_train, y_train)    \n",
    "\n",
    "#预测\n",
    "y_test_pred_ridge = ridge.predict(X_test)\n",
    "y_train_pred_ridge = ridge.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print ('The r2 score of RidgeCV on test is', r2_score(y_test, y_test_pred_ridge))\n",
    "print ('The r2 score of RidgeCV on train is', r2_score(y_train, y_train_pred_ridge))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 可视化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYsAAAEKCAYAAADjDHn2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XuYFPW95/H3d+7cBOSi3AcUxQsGdUDlYkzEiJrFaDS6\nGuMF8PGc+Jxks2c35kme5Fmz2T3H7GZ3zx5zEkGC6yUYNZ5wFDUmxjgoCIMiiKLiDJeBQQaU4T63\n/u4fXUAz9kz3MFNd3T2f1/PwdHXVr6q+Uz3UZ6q6qn7m7oiIiHSkIOoCREQk+yksREQkJYWFiIik\npLAQEZGUFBYiIpKSwkJERFJSWIiISEoKCxERSUlhISIiKRVFXUB3GTx4sJeXl0ddhohITlm9evUu\ndx+Sql3ehEV5eTlVVVVRlyEiklPMbHM67XQaSkREUlJYiIhISgoLERFJSWEhIiIpKSxERCQlhYWI\niKSksBARkZQUFiIiOezZt2t5enUtYXeRrbAQEclRza0xHnjxA37/Vi1mFuq6FBYiIjnq+bV11DUc\nZt6McaGvS2EhIpKD3J35ldWcPrQvXzwj5aOdukxhISKSg5ZX72b99r3MnT6WgoJwT0GBwkJEJCct\nqKxhUJ8Svnb+iIysT2EhIpJjNu7cxysbdnLbJWMoKy7MyDoVFiIiOebhZTWUFhVw28VjMrZOhYWI\nSA7Ztb+RZ97axvUXjGRQ39KMrVdhISKSQx5dvpmmlhhzpo/N6HoVFiIiOeJwcyuPrtjM5ROGcvrQ\nvhldt8JCRCRH/P6tbXx6oIm5GbgJry2FhYhIDojFnIeXVXPuiJO4eNzJGV+/wkJEJAe8+uFOPq4/\nwLwZ40J/DlQyCgsRkRww/7UahvUv4+qJwyJZv8JCRCTLvbutgeXVu7lzWjnFhdHs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Qk\nJYWF9Hhmtr+L8z8d3BneUZtXrYOn9abbpk37IWb2YrrtRbpCYSHSBcFzgQrdvTrT63b3eqDOzKZl\net3S8ygsRALBXa8/N7N3Ld5XyE3B+ILgkQ7rzew5M1tqZjcEs91Kwl3jZvYvwQML15vZf2lnPfvN\n7H+a2Vtm9mczG5Iw+UYzW2lmH5rZjKB9uZlVBu3fMrOpCe3/NahBJFQKC5FjrgcmAV8AZgI/Dx6D\ncT1QDkwE5gKXJMwzDVid8P6H7l4BnAd80czOS7KePsBb7n4B8FfgJwnTitx9CvDdhPE7gSuC9jcB\n/5TQvgqY0fkfVaRz8vpBgiKdNJ34k1dbgU/M7K/A5GD8U+4eA3aY2V8S5hkG1Ce8/0bwyPiiYNrZ\nxB/PkCgGPBkMPwYkPhDuyPBq4gEFUAz8s5lNAlqBMxLa7yT+yBWRUCksRI5prxOijjonOkT8eU+Y\n2Vjg74HJ7v6ZmS06Mi2FxGfuNAavrRz7//kfiD+P6wvEzwYcTmhfFtQgEiqdhhI55jXgJjMrDL5H\nuJT4w/6WEe8YqMDMTiHereYR7wOnB8MnAQeAhqDdVe2sp4D4E2cBbgmW35H+QF1wZHMb8W5SjziD\n7HjisOSHzs5cAAAA2ElEQVQ5HVmIHPMs8e8j3iH+1/5/dvcdZvYMcDnxnfKHxHsnawjmeZ54ePzJ\n3d8xs7eJP5G0Gni9nfUcAM4xs9XBcm5KUdcvgWfM7EbiT4Q9kDDtS0ENIqHSU2dF0mBmfT3eM9og\n4kcb04Ig6UV8Bz4t+K4jnWXtd/e+3VTXa8C17v5ZdyxPpD06shBJz3NmNgAoAX7q7jsA3P2Qmf2E\neD/HWzJZUHCq7BcKCskEHVmIiEhK+oJbRERSUliIiEhKCgsREUlJYSEiIikpLEREJCWFhYiIpPT/\nAaEwgOfuPbzoAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a17056240>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 0.01\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "(9,)"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mse_mean = np.mean(ridge.cv_values_, axis = 0)\n",
    "plt.plot(np.log10(alphas), mse_mean.reshape(len(alphas),1)) \n",
    "\n",
    "#这是为了标出最佳参数的位置，不是必须\n",
    "#plt.plot(np.log10(ridge.alpha_)*np.ones(3), [0.28, 0.29, 0.30])\n",
    "\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()\n",
    "\n",
    "print ('alpha is:', ridge.alpha_)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "# fs = pd.DataFrame({\"columns\":list(columns), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T))})\n",
    "# fs.sort_values(by=['coef_lr'],ascending=False)\n",
    "\n",
    "# columns.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 3.3 正则化的线性回归（L1正则 --> Lasso）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The r2 score of LassoCV on test is 0.706993155816\n",
      "The r2 score of LassoCV on train is 0.848985735475\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "/Users/lihuixiang/anaconda3/lib/python3.6/site-packages/sklearn/linear_model/coordinate_descent.py:1094: DataConversionWarning: A column-vector y was passed when a 1d array was expected. Please change the shape of y to (n_samples, ), for example using ravel().\n",
      "  y = column_or_1d(y, warn=True)\n"
     ]
    }
   ],
   "source": [
    "#### Lasso／L1正则\n",
    "# class sklearn.linear_model.LassoCV(eps=0.001, n_alphas=100, alphas=None, fit_intercept=True, \n",
    "#                                    normalize=False, precompute=’auto’, max_iter=1000, \n",
    "#                                    tol=0.0001, copy_X=True, cv=None, verbose=False, n_jobs=1,\n",
    "#                                    positive=False, random_state=None, selection=’cyclic’)\n",
    "from sklearn.linear_model import LassoCV\n",
    "\n",
    "#设置超参数搜索范围\n",
    "#alphas = [ 0.01, 0.1, 1, 10,100]\n",
    "\n",
    "#生成一个LassoCV实例\n",
    "#lasso = LassoCV(alphas=alphas)  \n",
    "lasso = LassoCV()  \n",
    "\n",
    "#训练（内含CV）\n",
    "lasso.fit(X_train, y_train)  \n",
    "\n",
    "#测试\n",
    "y_test_pred_lasso = lasso.predict(X_test)\n",
    "y_train_pred_lasso = lasso.predict(X_train)\n",
    "\n",
    "\n",
    "# 评估，使用r2_score评价模型在测试集和训练集上的性能\n",
    "print ('The r2 score of LassoCV on test is', r2_score(y_test, y_test_pred_lasso))\n",
    "print ('The r2 score of LassoCV on train is', r2_score(y_train, y_train_pred_lasso))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8leWZ//HPlR0SCFvYCfsiKiAEFHEBV+pYrVZrba24\ntNS21unM2Nb+rLVTZ6bt2E5tp1rHWsWlal3QYl1ww6VuGED2VdawJZANsi/X749zSCMm5EDy5Jzk\nfN+vV16c5c55rpuTnG/u+3me+zF3R0REBCAh2gWIiEjsUCiIiEgDhYKIiDRQKIiISAOFgoiINFAo\niIhIA4WCiIg0UCiIiEgDhYKIiDRIinYBR6tPnz4+bNiwaJchItKhLFmyZJ+7Z7XUrsOFwrBhw8jN\nzY12GSIiHYqZbYuknaaPRESkgUJBREQaKBRERKSBQkFERBooFEREpIFCQUREGigURESkgUJBRKQD\n+O1rG1mRVxz4djrcyWsiIvFm0fp8fvPaBmrr65kwuEeg29JIQUQkhh2orOHW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0uD/Az5Z81UgmJaDAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a17056320>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 0.000411712570536\n"
     ]
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3), [0.3, 0.4, 1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()    \n",
    "           \n",
    "print ('alpha is:', lasso.alpha_)\n",
    "\n",
    "# 看看各特征的权重系数，系数的绝对值大小可视为该特征的重要性\n",
    "# fs = pd.DataFrame({\"columns\":list(columns), \"coef_lr\":list((lr.coef_.T)), \"coef_ridge\":list((ridge.coef_.T)), \"coef_lasso\":list((lasso.coef_.T))})\n",
    "# fs.sort_values(by=['coef_lr'],ascending=False)\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAYUAAAEKCAYAAAD9xUlFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3Xl8leWZ//HPlR0SCFvYCfsiKiAEFHEBV+pYrVZrba24\ntNS21unM2Nb+rLVTZ6bt2E5tp1rHWsWlal3QYl1ww6VuGED2VdawJZANsi/X749zSCMm5EDy5Jzk\nfN+vV16c5c55rpuTnG/u+3me+zF3R0REBCAh2gWIiEjsUCiIiEgDhYKIiDRQKIiISAOFgoiINFAo\niIhIA4WCiIg0UCiIiEgDhYKIiDRIinYBR6tPnz4+bNiwaJchItKhLFmyZJ+7Z7XUrsOFwrBhw8jN\nzY12GSIiHYqZbYuknaaPRESkgUJBREQaKBRERKSBQkFERBooFEREp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9wsxuJ3QN3+3tWVB4iut/FAjSHjRSEBGRBtrRLCIi\nDRQKIiLSQKEgIiINFAoiItJAoSAiIg0UCiIi0uD/Az5Z81UgmJaDAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure at 0x1a17b98550>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "alpha is: 0.000411712570536\n"
     ]
    }
   ],
   "source": [
    "mses = np.mean(lasso.mse_path_, axis = 1)\n",
    "plt.plot(np.log10(lasso.alphas_), mses) \n",
    "#plt.plot(np.log10(lasso.alphas_)*np.ones(3), [0.3, 0.4, 1.0])\n",
    "plt.xlabel('log(alpha)')\n",
    "plt.ylabel('mse')\n",
    "plt.show()    \n",
    "            \n",
    "print ('alpha is:', lasso.alpha_)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
